/**
 * Copyright (C), 2015-2024, XXX有限公司
 * FileName: DataBase
 * Author:   mac
 * Date:     2024/3/8 18:22
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.finsiot.tools.taos.migration.bean;

import lombok.Data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author zhangtianchang
 * @create 2024/3/8
 * @since 1.0.0
 */

@Data
public class DataBase {

    private String host;

    private Integer port;

    private String database;

    private String username;

    private String password;


    private String precision;

    private Integer keep;

    public DataBase(){

    }
    public DataBase(String host, Integer port, String database, String username, String password, String precision,Integer keep){
        this.host=host;
        this.port=port;
        this.database=database;
        this.username=username;
        this.password=password;
        this.precision=precision;
        this.keep=keep;
    }
    public Connection createConnection() {
        try {
            Class.forName("com.taosdata.jdbc.rs.RestfulDriver");

            String jdbcUrl = "jdbc:TAOS-RS://" + host + ":" + port + "/" + database + "?user=" + username + "&password=" + password;

        return  DriverManager.getConnection(jdbcUrl);
        } catch (ClassNotFoundException e) {
            System.out.println("ERROR Message: " + e.getMessage());
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println("ERROR Message: " + e.getMessage());
            System.out.println("ERROR Code: " + e.getErrorCode());
            e.printStackTrace();
        }
        return null;
    }
}